package com.gpslw.mvc.controller;

import com.alibaba.fastjson.JSONObject;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import com.gpslw.mvc.bean.Person;
import com.gpslw.mvc.config.MvcProperties;
import com.gpslw.mvc.config.SystemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.time.LocalDate;
import java.util.Date;

@RestController
@RequestMapping(value = "/params/")
public class ParamController {

    Class clazz = ParamController.class;
    Logger logger = LoggerFactory.getLogger(clazz);

    @Value("${name:1234}")
    private String name;

    @Autowired
    private SystemService systemService;

    @Autowired
    private MvcProperties mvcProperties;

    @GetMapping(value = "body")
    public Person body(@Validated @RequestBody Person person){
        System.out.printf(JSONObject.toJSONString(person));
        systemService.getSystemUser();
        return person;
    }

    @GetMapping(value = "form")
    public Person form(@Validated Person person){
        System.out.printf(JSONObject.toJSONString(person));
        return person;
    }

    @GetMapping(value = "params")
    public Person params(@Validated Person person){
        System.out.println(JSONObject.toJSONString(person));
        return person;
    }

    @GetMapping(value = "mvcValue")
    public String getFormatDate(){
        logger.info("name========" +name);
        return mvcProperties.getName();
    }

    @GetMapping(value = "mvcNowValue")
    public Person getNowDate(){
        Person person = new Person();
        person.setBirthDay(LocalDate.now());
        logger.info("name=======" +name);
        return person;
    }

    @GetMapping(value = "mvcNowFormat")
    public Date mvcNowFormat(){
        return new Date();
    }

}
